<template>
	<view class="content">
		<f-navbar title="我的余额" fontColor="#333" fontSize="34" gradient="linear-gradient(-90deg,#E7D9CE, #F8F4F1 )">
			<view class="u-flex" slot="left">
				<van-icon name="arrow-left" color="#333" size="20" />
			</view>
		</f-navbar>
		<view class="content_box">
			<view class="content_top">
				<view class="balancetitle" @click="openpopup">
					可用余额
					<van-icon class="balanceitoast" name="question" color="#999" size="12" />
				</view>
				<view class="balance_price">
					￥
					<text class="balance_priceicon">{{dataobj.balance_amount}}</text>

				</view>
				<view class="balance_box">
					<view class="balance_boxL">
						<view class="balance_boxLtitle">
							总付款笔数
						</view>
						<view class="balance_boxLnum">
							{{dataobj.total_count}}笔
						</view>
					</view>
					<view class="balance_boxLine">

					</view>
					<view class="balance_boxR">
						<view class="balance_boxRtitle">
							总余额
						</view>
						<view class="balance_boxRnum">
							<text class="balance_boxRnumicon">￥</text>{{dataobj.total_balance}}
						</view>
					</view>
				</view>
			</view>
			<view class="content_top1">

			</view>
			<view class="balance_info">


					<view class="balance_infotop">
						
						<view class="goumaitime">
							购买时间
						</view>
						<view class="dingdannum">
							购买价
						</view>
						<view class="zuizhongjia">
							最终价
						</view>
						<view class="shuliang">
							数量
						</view>
						<view class="fancha">
							返差额
						</view>
					</view>
					<scroll-view @scrolltolower="lowerBottom" scroll-y="true" class="scrollHeight"
						:style="{marginTop:0+'rpx'}" :scroll-top="scrollTop" :refresher-threshold="100"
						:refresher-triggered="triggered" :scroll-with-animation="true">
					<view class="balance_infoitem" v-for="(item,index) in dataList" :key="index" @click="ondetail(item)">
						
						<view class="goumaitime1">
							{{item.buy_time}}
						</view>
						<view class="dingdannum1">
							￥{{item.tree_price}}
						</view>
						<view class="zuizhongjia1">
							￥{{item.final_price}}
						</view>
						<view class="shuliang1">
							 {{item.buy_num}}
						</view>
						<view class="fancha1">
							￥{{item.balance_amount}}
							<van-icon class="right_icon" name="arrow" color="#bbb" size="12" />
						</view>
					</view>
					</scroll-view>
				
			</view>
		</view>
		<van-dialog title="我的余额" width="240" :message="dataobj.txt" :show="isshow" @confirm="onconfirm" />
	</view>
</template>

<script>
	import fNavbar from '@/uni_modules/f-navbar/components/f-navbar/f-navbar.vue';
	import {
		getUserBalance
	} from '../../../utils/app.js'
	export default {
		components: {
			fNavbar
		},
		data() {
			return {
				imgurl: getApp().globalData.imgurl,
				pages: 1, // 分页数据
				PageSize: 4, // 一页有多少数据
				total: null, // 总条数	
				dataList: [], // 列表数据
				triggered: false, // 设置是否下拉
				scrollTop: 0,
				dataobj: {}, //金额
				isshow:false, // 我的余额弹窗
			}
		},
		onLoad() {
			this.getList(true)
		},
		methods: {
			// 点击条撞到详情
			ondetail(e){
				uni.navigateTo({
					url: '/pages/subPack/orderDetail/orderDetail?tradeNo=' + e.order_no + '&status=' + 4
				})
			},
			// 点击确认关闭弹窗
			onconfirm(){
				this.isshow = false
			},
			// 打开我的余额弹窗
			openpopup(){
				this.isshow = true
			},
			//触底加载
			lowerBottom() {
				// 判断是否还有下一页数据
				// if (this.pages * this.PageSize >= this.total) return person.showMoreData = true
				// 让页码值自增 +1
				// console.log('999');
				// this.pages += 1
				// 重新获取列表数据
				this.getList(false)
			},
			// 下拉刷新
			// getFresh() {
			// 	this.triggered = true,
			// 	this.getList(true)

			// },
			// 获取数据
			getList(isPullDownRefresh) {
				let currPage = 1
				if (!isPullDownRefresh) {
					currPage = this.pages + 1
				} else {
					currPage = 1
				}
				getUserBalance({
					page: currPage
				}).then(res => {
					console.log(res);
					if (res.code == 1) {
						this.dataobj = res.data.base
						uni.hideToast()
						const newdata = res.data.list.list
						if (isPullDownRefresh) {
							this.dataList = newdata
							this.triggered = false
						} else {
							this.dataList = [...this.dataList, ...newdata]
						}
						this.pages = res.data.list.page.current
						console.log(this.pages);
						// this.total = res.data.page.total
					}
				})
			},

		}
	}
</script>

<style>
	page {
		background: #eee;
	}


	.content_top {
		width: 100%;
		height: 210rpx;
		background: linear-gradient(to right, #F8F4F1, #E7D9CE);
		position: fixed;
		display: flex;
		flex-direction: column;
		align-items: center;
		/* justify-content: center; */
	}

	.content_top1 {
		height: 330rpx
	}

	.balancetitle {
		font-size: 32rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #A27147;
		margin-top: 50rpx;
	}

	.balanceitoast {
		margin-left: 10rpx;
	}

	.balance_price {
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: 700;
		color: #FF0000;
		margin-top: 15rpx;
		margin-bottom: 10rpx;
	}

	.balance_priceicon {
		font-size: 56rpx;
	}

	.balance_box {
		width: 690rpx;
		height: 146rpx;
		background: rgba(255, 255, 255, 0.9);
		box-shadow: 0rpx 3rpx 0rpx 0rpx rgba(233, 220, 210, 0.11);
		/* opacity: 0.9; */
		border-radius: 10rpx;
		position: absolute;
		bottom: -126rpx;
		display: flex;
		align-items: center;
		justify-content: space-evenly;
	}

	.balance_boxL {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.balance_boxLtitle {
		font-size: 30rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333333;

	}

	.balance_boxLnum {
		font-size: 30rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #FF0000;
		margin-top: 25rpx;

	}

	.balance_boxLine {
		width: 2rpx;
		height: 86rpx;
		background: #DEB491;
	}

	.balance_boxR {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.balance_boxRtitle {
		font-size: 30rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333333;

	}

	.balance_boxRnum {
		font-size: 30rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #FF0000;
		margin-top: 25rpx;

	}

	.balance_boxRnumicon {
		font-size: 22rpx
	}
	.scrollHeight{
		height: 60vh;
	}

	.balance_info {
		width: 690rpx;
		/* height: 1751rpx; */
		background: rgba(255, 255, 255, 0.9);
		box-shadow: 0rpx 3rpx 0rpx 0rpx rgba(233, 220, 210, 0.11);
		border-radius: 10rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		padding-bottom: 31rpx;
	}

	.balance_infotop {
		width: 690rpx;
		height: 72rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* background: #EEEEEE; */
	}

	.dingdannum {
		width: 135rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #A27147;
		line-height: 72rpx;
		text-align: center;
	}

	.goumaitime {
		width: 210rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #A27147;
		line-height: 72rpx;
		text-align: center;
	}

	.zuizhongjia {
		width: 135rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #A27147;
		line-height: 72rpx;
		text-align: center;
	}
	.shuliang{
		width: 135rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #A27147;
		line-height: 72rpx;
		text-align: center;
	}

	.fancha {
		width: 135rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #A27147;
		line-height: 72rpx;
		text-align: center;
	}

	.balance_infoitem {
		width: 684rpx;
		height: 72rpx;

		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.balance_infoitem:nth-child(2n) {
		background: #eee;
	}

	.dingdannum1 {
		width: 135rpx;
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333;
		line-height: 36rpx;
		text-align: center;
		word-wrap:break-word
	}

	.goumaitime1 {
		width: 210rpx;
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333;
		line-height: 36rpx;
		text-align: center;
		word-wrap:break-word
	}
	.shuliang1{
		width: 135rpx;
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333;
		line-height: 36rpx;
		text-align: center;
		word-wrap:break-word
	}

	.zuizhongjia1 {
		width: 135rpx;
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333;
		line-height: 36rpx;
		text-align: center;
		word-wrap:break-word
	}

	.fancha1 {
		width: 135rpx;
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333;
		line-height: 36rpx;
		text-align: center;
		position: relative;
		word-wrap:break-word
	}

	.right_icon {
		position: absolute;
		right: 8rpx;
		top: 50%;
		transform: translateY(-50%);
	}
</style>